import os


class FileUtil:

    @staticmethod
    def get_pro_path(pro_name):
        cur_path = os.path.abspath(os.path.dirname(__file__))
        try:
            root_path = cur_path[:cur_path.find(pro_name + "\\") + len(pro_name + "\\") - 1]
        except:
            root_path = cur_path[:cur_path.find(pro_name + "/") + len(pro_name + "/") - 1]
        return root_path

    @staticmethod
    def get_cur_path():
        return os.path.abspath(os.path.dirname(__file__))

    @staticmethod
    def get_root_path():
        cur_path = os.path.abspath(os.path.dirname(__file__))
        try:
            root_path = cur_path[:cur_path.index("\\lib")]
        except:
            root_path = cur_path[:cur_path.index("/lib")]
        return root_path

    @staticmethod
    def get_project_name():
        cur_path = os.path.abspath(os.path.dirname(__file__))
        try:
            root_path = cur_path[:cur_path.index("\\lib")]
            project_name = root_path[root_path.rfind("\\") + 1:]
        except:
            root_path = cur_path[:cur_path.index("/lib")]
            project_name = root_path[root_path.rfind("/") + 1:]
        return project_name

    @staticmethod
    def exists_file(path):
        # os.system(r"touch {}".format(path))
        return os.path.exists(path)

    @staticmethod
    def exists_folder(path):
        if not os.path.exists(path):
            os.makedirs(path)
